<script>
    var myAjax = function myAjax(param, api_url) {
    var obj_return;
    var token = getUrlParam("token");
    var randNum = RndNum();//随机生成6-12位数字
    var ts=Date.parse(new Date());
    if (token == null || token == "") {
        token = localStorage.getItem("token");
    }else{
        localStorage.setItem("token",token);//把从url中过去的token存到local里
    }
    var salt = localStorage.getItem("salt"); //用于接口校验
    var sign = $.md5(token+randNum+ts+salt);
    $.ajax({
        url: Server_Ip + api_url,
        type: "POST",
        async: false,
        dataType: "json",
        contentType: "application/json",
        data: param,
        headers: {
            "token": token,
            "rand":randNum,
            "ts":ts,
            "sign":sign,
            "salt":salt
        },
        timeout: 10000, //超时时间设置为10秒；
        success: function(data) {

            obj_return = data;

        },
        error: function(xhr, type, errorThrown) {
            alert(xhr.readyState);
        }
    });

    return obj_return;
}





Vue.prototype.postHttp = function(url, param) {
  var head_token = localStorage.getItem("token");
  Vue.http.headers.common['token']=head_token;
  return Vue.http.post('http://101.200.234.55:8080/medapp' + url, param);

}

Vue.prototype.postHttp = function(url, param) {
  var head_token = localStorage.getItem("token");
  Vue.http.headers.common['token']=head_token;
  return Vue.http.post('http://192.168.10.124:8080/oauth' + url, param);
}

//获取url中的参数
Vue.prototype.getUrlParam = function(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

//获取url中的参数
Vue.prototype.getUrlStrParam = function(str,name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = str.match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

</script>